package com.ktgj.hotel.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import com.ktgj.hotel.domain.DicElongCity;
import com.ktgj.hotel.domain.dic.CityNameList;
import com.ktgj.hotel.domain.dic.DicCityList;
import com.ktgj.hotel.domain.dic.DicCitysVo;
import com.ktgj.hotel.domain.vo.DicCountyVo;
import com.ktgj.hotel.utils.TimeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ktgj.hotel.mapper.DicCountyMapper;
import com.ktgj.hotel.domain.dic.DicCounty;
import com.ktgj.hotel.service.IDicCountyService;

/**
 * 【请填写功能名称】Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-10-28
 */
@Service
public class DicCountyServiceImpl implements IDicCountyService 
{
    @Autowired
    private DicCountyMapper dicCountyMapper;

    /**
     * 查询【请填写功能名称】
     * 
     * @param id 【请填写功能名称】ID
     * @return 【请填写功能名称】
     */
    @Override
    public DicCounty selectDicCountyById(Long id)
    {
        return dicCountyMapper.selectDicCountyById(id);
    }

    /**
     * 查询【请填写功能名称】列表
     * 
     * @param dicCounty 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<DicCounty> selectDicCountyList(DicCounty dicCounty)
    {
        return dicCountyMapper.selectDicCountyList(dicCounty);
    }

    /**
     * 新增【请填写功能名称】
     * 
     * @param dicCounty 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertDicCounty(DicCounty dicCounty)
    {
        return dicCountyMapper.insertDicCounty(dicCounty);
    }

    /**
     * 修改【请填写功能名称】
     * 
     * @param dicCounty 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateDicCounty(DicCounty dicCounty)
    {
        return dicCountyMapper.updateDicCounty(dicCounty);
    }

    /**
     * 批量删除【请填写功能名称】
     * 
     * @param ids 需要删除的【请填写功能名称】ID
     * @return 结果
     */
    @Override
    public int deleteDicCountyByIds(Long[] ids)
    {
        return dicCountyMapper.deleteDicCountyByIds(ids);
    }

    /**
     * 删除【请填写功能名称】信息
     * 
     * @param id 【请填写功能名称】ID
     * @return 结果
     */
    @Override
    public int deleteDicCountyById(Long id)
    {
        return dicCountyMapper.deleteDicCountyById(id);
    }

    /**
     * 查询全部县信息(远程)
     * */
    @Override
    public List<DicCountyVo> selectAllDicCountyList() {
        List<DicCounty> dicCountyList = dicCountyMapper.selectAllDicCountyList();
        List<DicCountyVo> dicCountyVoList = new ArrayList<>();

        for (DicCounty dicCounty : dicCountyList) {
            DicCountyVo dicCountyVo = new DicCountyVo();
            dicCountyVo.setId(dicCounty.getId());
            dicCountyVo.setCityId(dicCounty.getCityId());
            dicCountyVo.setCountyName(dicCounty.getCountyName());
            dicCountyVoList.add(dicCountyVo);
        }
        return dicCountyVoList;
    }

    /**
     * 跟据县、区名称查询信息（远程）
     * */
    @Override
    public DicCountyVo selectDicCountyByDicCountyId(String countyName) {
        DicCounty dicCounty = dicCountyMapper.selectDicCountyByDicCountyId("%" + countyName + "%");
        DicCountyVo dicCountyVo = new DicCountyVo();
        dicCountyVo.setId(dicCounty.getId());
        return dicCountyVo;
    }



    @Override
    public List<DicCityList> queryCountyList() {
        String[] letterList = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
                "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
        List<DicCityList> cityLists = new ArrayList<>();
        List<DicCitysVo> cityNameLists = dicCountyMapper.queryCountyList();
        if (cityNameLists.size() > 0) {
            for (int i = 0; i < letterList.length; ++i) {
                DicCityList cityList1 = new DicCityList();
                cityList1.setLetterNum(letterList[i]);
                List<CityNameList> cityNameList = new ArrayList<>();
                for (DicCitysVo nameList : cityNameLists) {
                    String pinyin = TimeUtils.getPinYinHeadChar(nameList.getCityName()).substring(0, 1);
                    if (letterList[i].equals(pinyin)) {
                        CityNameList cityNameList1 = new CityNameList();
                        cityNameList1.setCityName(nameList.getCityName());
                        cityNameList.add(cityNameList1);
                    }
                }
                cityList1.setCityNameLists(cityNameList);
                if (cityList1.getCityNameLists().size() > 0) {
                    cityLists.add(cityList1);
                }
            }
        }
        return cityLists;
    }

    /**
     * 根据市查询酒店筛选条件“行政区”
     * */
    @Override
    public List<DicCounty> conditionAdministrativeDistrict(Long cityId) {
        List<DicCounty> dicCountieList = dicCountyMapper.conditionAdministrativeDistrict(cityId);
        if (dicCountieList != null){
            //排除空值
            List<DicCounty> collect = dicCountieList.stream().filter(item -> {
                return item.getCountyName()!=null && item.getCountyName()!="";
            }).collect(Collectors.toList());

            return collect;
        }
        else {
            return null;
        }
    }

    /**
     * 酒店商圈列表
     * */
    @Override
    public List<DicCounty> county() {
        List<DicCounty> dicCountyList = dicCountyMapper.county();
        return dicCountyList;
    }
}
